package com.daedalus.Gui.shape;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.*;


public class Shape extends JPanel implements ActionListener{

	JRadioButton choice1= new JRadioButton("drejtkendesh");
	JRadioButton choice2= new JRadioButton("oval");
	
	JTextField x = new JTextField("X-koordinate");
	JTextField y = new JTextField("Y-koordinate");
	JTextField width = new JTextField("Gjeresia");
	JTextField height = new JTextField("Gjatesia");
	
	JButton button=new JButton("draw");
	
	public Shape(){
		setSize(500,650);
		setLayout(null);

		choice1.setSize(100, 30);
		choice2.setSize(100, 30);
		x.setSize(100, 30);
		y.setSize(100, 30);
		width.setSize(100, 30);
		height.setSize(100, 30);
		button.setSize(100, 40);

		choice1.setLocation(0, 500);
		choice2.setLocation(0, 550);
		x.setLocation(150, 500);
		y.setLocation(150, 550);
		width.setLocation(300, 500);
		height.setLocation(300, 550);
		button.setLocation(430, 520);

		add(choice1);
		add(choice2);
		add(x);
		add(y);
		add(width);
		add(height);
		add(button);
		button.addActionListener(this);
		choice1.addActionListener(this);
		choice2.addActionListener(this);
	}
	
	
	private void  drawShape(int x,int y,int w,int h,int choice){
		KomponentiGrafik c=new KomponentiGrafik(x,y,w,h,choice);
		add(c);
		setComponentZOrder(c,0);
		repaint();
	}
	
	@Override
	public void actionPerformed(ActionEvent e) {
		if(e.getSource()==choice1){
			choice2.setSelected(false);
		}
		else if(e.getSource()==choice2){
			choice1.setSelected(false);
		}

		
		else if(e.getSource()==button){
			int x = Integer.parseInt(this.x.getText());
			int y = Integer.parseInt(this.y.getText());
			int w = Integer.parseInt(width.getText());
			int h = Integer.parseInt(height.getText());
		
			if(choice1.isSelected() && !choice2.isSelected())
				drawShape(x,y,w,h,1);
			if(!choice1.isSelected() && choice2.isSelected())
				drawShape(x,y,w,h,2);
		}
	}
}
